package sdfi.lee.test;

	import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.Topic;
import javax.management.ObjectName;
import javax.management.QueryExp;

import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.advisory.DestinationSource;
import org.apache.activemq.broker.Broker;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.jmx.BrokerView;
import org.apache.activemq.broker.jmx.BrokerViewMBean;
import org.apache.activemq.broker.jmx.ConnectionViewMBean;
import org.apache.activemq.broker.jmx.ConnectorViewMBean;
import org.apache.activemq.broker.jmx.DestinationViewMBean;
import org.apache.activemq.broker.jmx.DurableSubscriptionViewMBean;
import org.apache.activemq.broker.jmx.JobSchedulerViewMBean;
import org.apache.activemq.broker.jmx.ManagedRegionBroker;
import org.apache.activemq.broker.jmx.ManagementContext;
import org.apache.activemq.broker.jmx.NetworkBridgeViewMBean;
import org.apache.activemq.broker.jmx.NetworkConnectorViewMBean;
import org.apache.activemq.broker.jmx.QueueViewMBean;
import org.apache.activemq.broker.jmx.SubscriptionViewMBean;
import org.apache.activemq.broker.jmx.TopicViewMBean;
import org.apache.activemq.broker.region.Queue;
import org.apache.activemq.broker.region.policy.ConstantPendingMessageLimitStrategy;
import org.apache.activemq.broker.region.policy.PolicyEntry;
import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQTopic;
import org.apache.activemq.transport.TransportListener;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
	  
	/** 
	 * 监控ActiveMQ的各种信息Broker,Connection,Queue,Topic的数量和压栈和出栈 
	 * @author longgangbai 
	 * 
	 */  
	public class DeleteDestination {  
	    
	        protected static final int MESSAGE_COUNT = 2000;  
	        protected static String bindAddress ="tcp://localhost:61616";  
	        //ActiveMQConnectionFactory.DEFAULT_BROKER_BIND_URL;  
	     
	        private static Connection createConnection(final boolean start) throws JMSException {
	            ConnectionFactory cf = new ActiveMQConnectionFactory(bindAddress);
	            Connection conn = cf.createConnection();
	            if (start) {
	                conn.start();
	            }
	            return conn;
	        }
	        public static void main(String[] arg) throws JMSException
	        {
	        		//deleteDestination.action?JMSDestination=q-8335095CB&JMSDestinationType=queue&secret=d4c108e7-4c61-4dfa-9f94-fbf9dba0edb4
	        	 ActiveMQConnection amqConnection = (ActiveMQConnection) createConnection(true);
	        	 
	          //   DestinationSource destinationSource = amqConnection.getDestinationSource();
	             
	             Session session = amqConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
	            // Topic topic = session.createTopic("TEST.FOO");
	            Destination topic=session.createQueue("activemq.queue1");
	          //   MessageProducer producer = session.createProducer(topic);
	            // MessageConsumer consumer = session.createConsumer(topic);

//	             TextMessage msg = session.createTextMessage("Hellow World");
//	             producer.send(msg);

	            // ActiveMQ amqTopic = (ActiveMQTopic)topic;
//	             consumer.close();
//	             producer.close();
	             session.close();
	            
	             // This line generates a broker error since the consumer is still active.
	             try{
	                 amqConnection.destroyDestination( (ActiveMQDestination)topic );
	             } catch( JMSException expected ) {
	             }
	             amqConnection.close();

	        }
	          
	} 

